home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / addTextureToShaderLayered.me < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.8 KB  |  126 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Procedure: addTextureToShaderLayered
  19. //
  20. // Description:
  21. //
  22. //        Add a file texture to a shader node's color connection
  23. //        with either adding a new layered texture in between,
  24. //        or adding a new layer to an existing layered texture
  25. //        connection
  26. //
  27. // Arguments:
  28. //        shader : shader / shading engine to add to
  29. //        thisTexture : texture to add
  30. //        killColorLayer : replace color layer in layered texture
  31. //        connectAlpha : connect alpha of texture to layered texture alpha
  32. //
  33. // Author : Bernard Kwok
  34. // Last Updated : 07/18/00
  35. //
  36. proc string plugNode( string $plug )
  37. {
  38.     string $buffer[];
  39.     tokenize($plug, ".", $buffer);
  40.     return $buffer[0];
  41. }
  42.  
  43. global proc addTextureToShaderLayered(string $shader, 
  44.                                       string $thisTexture,
  45.                                       int $blendMode,
  46.                                       int $killColorLayer,
  47.                                       int $connectAlpha)
  48. {
  49.     //if (size($shader) == 0)
  50.     //    error ("No shader name passed to addTextureToShaderLayered()");
  51.     //if (size($thisTexture) == 0);
  52.     //    error ("No texture name passed to addTextureToShaderLayered()");
  53.  
  54.     // Check to see if we got passed in a shading engine
  55.     string $shaderAttr = ".color";
  56.     string $sType[] = `ls -showType $shader`;
  57.     if ($sType[1] == "shadingEngine")
  58.     {
  59.         string $shaders[] = `listConnections -d 1 ($shader+".surfaceShader")`;
  60.         $shader = $shaders[0];
  61.         if (size($shader) == 0)
  62.             $shaderAttr = ".surfaceShader";
  63.     }
  64.  
  65.     // Check if the shader already has a layered texture
  66.     // if so use it.
  67.     string $colorCons[] = `listConnections -d on -p on ($shader+$shaderAttr)`;
  68.  
  69.     string $layeredTx = "";
  70.     string $existingTx = "";
  71.     if (size($colorCons))
  72.     {
  73.         string $node = `plugNode $colorCons[0]`;
  74.         string $nType[] = `ls -showType $node`;
  75.         if ($nType[1] == "layeredTexture")
  76.         {
  77.             $layeredTx = $nType[0];
  78.         }
  79.         // See if its any kind of texture
  80.         else
  81.         {
  82.             string $allTex[] = `ls -tex`;
  83.             for ($i = 0; $i < size($allTex); $i++)
  84.             {
  85.                 if ($node == $allTex[$i])
  86.                 {
  87.                     $existingTx = $node;
  88.                     break;
  89.                 }
  90.             }
  91.         }
  92.     }
  93.  
  94.     // Break old non-layered texture connection
  95.     if (size($layeredTx) == 0)
  96.     {
  97.         if (size($colorCons))
  98.         {
  99.             disconnectAttr ($colorCons[0]) ($shader+$shaderAttr);
  100.  
  101.             // If there was an existing texture than hook that up
  102.             // to the layered texture first.
  103.             if (size($existingTx))
  104.             {
  105.                 $layeredTx = addToLayeredTx( $layeredTx, $existingTx, $blendMode, 0, 0);
  106.                 //print ("Add existing to layered tex " + $layeredTx + "\n");
  107.             }
  108.         }
  109.  
  110.         // Hook the file texture to the layered texture.
  111.         $layeredTx = addToLayeredTx( $layeredTx, $thisTexture, $blendMode, $killColorLayer, $connectAlpha );
  112.  
  113.         // Hook the layered texture up to the shader
  114.         connectAttr ($layeredTx+".outColor") ($shader+$shaderAttr);
  115.     }
  116.     else
  117.     {    
  118.         // If there was an existing texture than hook that up
  119.         // to the layered texture first.
  120.  
  121.         // Just hook up the file texture to the existin layered texture
  122.         addToLayeredTx( $layeredTx, $thisTexture, $blendMode, $killColorLayer, $connectAlpha );
  123.     }
  124. }
  125.  
  126.